import DS from 'ember-data';
import BaseModel from './base-model';
const {leaveStatus1,leaveStatus2,leaveStatus3,consultStatus6,consultStatus7} = Constants;

var Customerbusinessflow = BaseModel.extend({
  dateService: Ember.inject.service("date-service"),
  createUser:DS.belongsTo('user'),//创建人
  lastUpdateUser:DS.belongsTo('user'),//更改者
  createDateTime:DS.attr('number'),//创建时间
  lastUpdateTime:DS.attr('number'),//更改时间
  advTel:DS.attr('string'),//咨询人电话
  advName:DS.attr('string'),//咨询人姓名
  isDirectOrder:DS.attr('number'),//是否直接预定，0不是，1是
  orderDate:DS.attr('number'),//办理预定时间
  orderStaff:DS.belongsTo('user'),//办理预定员工
  orderMoney:DS.attr('string'),//保证金金额
  orderBed:DS.belongsTo('bed'),//预定床位号
  orderInTime:DS.attr('number'),//入院时间
  orderRemark:DS.attr('string'),//预定备注

  experienceDate:DS.attr('number'),//办理试住日期
  experienceStaff:DS.belongsTo('user'),//办理试住员工
  experienceStartTime:DS.attr('number'),//试住开始时间
  experienceEndTime:DS.attr('number'),//试住结束时间
  experienceBed:DS.belongsTo('bed'),//试住床位号
  experienceRemark:DS.attr('string'),//试住备注
  experienceNursingGrade:DS.belongsTo('nursinglevel'),//试住护理级别
  experienceReferencePrice:DS.attr('string'),//试住参考价格
  experiencePrice:DS.attr('string'),//试住实际价格

  checkInDate:DS.attr('number'),//办理入住日期
  checkInStaff:DS.belongsTo('user'),//办理入住员工
  checkInStartTime:DS.attr('number'),//入住开始时间
  checkInEndTime:DS.attr('number'),//入住结束时间
  checkInRemark:DS.attr('string'),//入住备注
  checkInNursingGrade:DS.belongsTo('nursinglevel'),//入住护理级别
  checkInReferencePrice:DS.attr('string'),//入住参考价格
  checkInPrice:DS.attr('string'),//入住实际价格
  checkInBed:DS.belongsTo('bed'),//入住床位号

  leaveDate:DS.attr('number'),//退住日期
  leaveRecordDate:DS.attr('number'),//退住登记日期
  leaveStaff:DS.belongsTo('user'),//办理退住员工
  leaveRemark:DS.attr('string'),//退住备注
  leaveStatus:DS.belongsTo('dicttype'),//退住状态

  customerAddr:DS.attr('string'),//老人地址
  customerBrith:DS.attr('number'),//老人生日
  customerCardCode:DS.attr('number'),//老人身份证号
  customerTel:DS.attr('string'),//老人电话
  customerEducation:DS.belongsTo('dicttype'),//老人教育级别
  customerGender:DS.belongsTo('dicttype'),//老人性别
  customerName:DS.attr('string'),//老人姓名
  customerNative:DS.belongsTo('dicttype'),//老人籍贯
  customerPS:DS.attr('string'),//老人身体情况
  consultRelation:DS.belongsTo('dicttype'),//咨询人与老人关系
  customerSelfCareAbility:DS.belongsTo('dicttype'),//老人自理能力
  customerNationality:DS.belongsTo('dicttype'),//老人民族
  status:DS.belongsTo('dicttype'),//入住状态
  customer:DS.belongsTo('customer'),//老人（办理试住或入住时生成老人信息）
  consultInfo:DS.belongsTo('consultinfo'),//咨询表
  tempFlag:DS.attr('number'),//办理状态:暂存标识，1暂存，0否
  diningStandard:DS.belongsTo('dicttypetenant'),//餐饮标准


  cusName:Ember.computed.alias('customer.name'),
  cusCardCode:Ember.computed.alias('customer.cardCode'),
  cusSex:Ember.computed.alias('customer.sex'),
  cusEdu:Ember.computed.alias('customer.educationLevel'),
  cusCare:Ember.computed.alias('customer.selfCareAbility'),
  cusNative:Ember.computed.alias('customer.customerNative'),
  cusTel:Ember.computed.alias('customer.phone'),

  telphone:Ember.computed('advTel','cusTel',function(){
    let advTel = this.get('advTel');
    let cusTel = this.get('cusTel');
    console.log('tel:',advTel,cusTel);
    console.log('id:',this.get('id'));
    if(cusTel){
      return cusTel;
    }else{
      return advTel;
    }
  }),

  tempFlagName:Ember.computed('tempFlag',function(){
    let temp = this.get('tempFlag');
    if(temp){
      if(temp==1){
        return '暂存';
      }
    }
  }),

  leaveStatusTypecodNumber:Ember.computed("leaveStatus",function(){
    var leaveStatus = this.get("leaveStatus");
    if(leaveStatus.get("typecode")===Constants.leaveStatus3){
      return 1;
    }
  }),
  customerStatus:Ember.computed("leaveStatus",function(){

    var leaveStatus = this.get("leaveStatus");
    var str = "";
    if(leaveStatus.get("typecode")===Constants.leaveStatus1){
      str = "申请退住";
    }else if(leaveStatus.get("typecode")===Constants.leaveStatus2){
      str = "费用结算中";
    }else if(leaveStatus.get("typecode")===Constants.leaveStatus3){
      str = "完成退住";

    }else if(status.get("typecode")===Constants.consultStatus7){
      str = "已作废";

    }
    return str;
  }),

  customerStatusClick:Ember.computed("leaveStatus",function(){
    var leaveStatus = this.get("leaveStatus");
    var str = "";
    if(leaveStatus.get("typecode")===Constants.leaveStatus1){
      str = "结算费用";

    }
    else if(leaveStatus.get("typecode")===Constants.leaveStatus2){
      str = "完成结算";
    }
    // else if(leaveStatus.get("typecode")===Constants.leaveStatus3){
    //   str = ""
    // }
    return str;
  }),

  theLeaveDate:Ember.computed("leaveDate",function(){
    var leaveDate = this.get("leaveDate");
    return this.get("dateService").timestampToTime(leaveDate);
  }),
  leaveDateString:Ember.computed("leaveDate",function(){
    var leaveDate = this.get("leaveDate");
    return this.get("dateService").formatDate(leaveDate,"yyyy-MM-dd");
  }),

  theLeaveRecordDate:Ember.computed("leaveRecordDate",function(){
    var leaveRecordDate = this.get("leaveRecordDate");
    // if(leaveRecordDate){
    //   leaveRecordDate = leaveRecordDate;
    // }else {
    //   leaveRecordDate = (new Date().getTime()/1000).toFixed(0);
    // }
    return this.get("dateService").timestampToTime(leaveRecordDate);
  }),
  leaveRecordDateString:Ember.computed("leaveRecordDate",function(){
    var leaveRecordDate = this.get("leaveRecordDate");
    return this.get("dateService").formatDate(leaveRecordDate,"yyyy-MM-dd");
  }),


  operatingName:Ember.computed('status',function(){
    let status = this.get('status');
    let name = '';
    if(status){
      if(status.get('typecode')=='consultStatus3'){
        name = '预定转试住';
      }
      if(status.get('typecode')=='consultStatus4'){
        name = '试住转入住';
      }
    }
    return name;
  }),
  //入院时间
  orderTime:Ember.computed('orderInTime',function(){
    let orderDate = this.get("orderInTime");
    return this.get("dateService").formatDate(orderDate,"yyyy-MM-dd");
  }),
  //预定办理时间
  orderDateTime:Ember.computed('orderDate',function(){
    let orderDate = this.get("orderDate");
    return this.get("dateService").formatDate(orderDate,"yyyy-MM-dd");
  }),
  //试住开始时间
  experienceStartTimeDate:Ember.computed('experienceStartTime',function(){
    let experienceStartTimeDate = this.get('experienceStartTime');
    return this.get("dateService").formatDate(experienceStartTimeDate,"yyyy-MM-dd");
  }),
  //试住结束时间
  experienceEndTimeDate:Ember.computed('experienceEndTime',function(){
    let experienceEndTimeDate = this.get('experienceEndTime');
    return this.get("dateService").formatDate(experienceEndTimeDate,"yyyy-MM-dd");
  }),
  //试住办理时间
  experienceDateTime:Ember.computed('experienceDate',function(){
    let experienceDate = this.get("experienceDate");
    return this.get("dateService").formatDate(experienceDate,"yyyy-MM-dd");
  }),
  //入住开始时间
  checkInStartTimeDate:Ember.computed('checkInStartTime',function(){
    let checkInStartTimeDate = this.get('checkInStartTime');
    return this.get("dateService").formatDate(checkInStartTimeDate,"yyyy-MM-dd");
  }),
  //入住结束时间
  checkInEndTimeDate:Ember.computed('checkInEndTime',function(){
    let checkInEndTimeDate = this.get('checkInEndTime');
    return this.get("dateService").formatDate(checkInEndTimeDate,"yyyy-MM-dd");
  }),
  //入住办理时间
  checkInDateTime:Ember.computed('checkInDate',function(){
    let checkInDate = this.get("checkInDate");
    return this.get("dateService").formatDate(checkInDate,"yyyy-MM-dd");
  }),
  //分配的床位信息
  bed:Ember.computed('status','orderBed','checkInBed','experienceBed',function(){
    let status = this.get('status');
    let bed;
    if(status){
      if(status.get('typecode')=='consultStatus3'){
        bed = this.get('orderBed');
      }
      if(status.get('typecode')=='consultStatus4'){
        bed = this.get('experienceBed');
      }
      if(status.get('typecode')=='consultStatus5'){
        bed = this.get('checkInBed');
      }
    }
    return bed;
  }),
  //经办人信息
  staff:Ember.computed('status','orderStaff','checkInStaff','experienceStaff',function(){
    let status = this.get('status');
    let staff;
    if(status){
      if(status.get('typecode')=='consultStatus3'){
        staff = this.get('orderStaff');
      }
      if(status.get('typecode')=='consultStatus4'){
        staff = this.get('experienceStaff');
      }
      if(status.get('typecode')=='consultStatus5'){
        staff = this.get('checkInStaff');
      }
    }
    return staff;
  }),
});

export default Customerbusinessflow;
